//es6的对象混入
interface Name {
  name: string
}
interface Age {
  age: number
}
interface Sex {
  sex: number
}
let peop = {
  name: '小杰'
}
let peop2 = {
  age: 123
}
let peop3 = {
  sex: 1
}
let newPeop = (<any>Object).assign(peop, peop2, peop3)
console.log(newPeop);

//类的混入
class AAA {
  types: boolean = false
  change() {
    return this.types = !this.types
  }
}
class BBB {
  name: string = '你好'
  getName(): string {
    return this.name
  }
}
//创建一个类 结合这两个Mixins
class C implements AAA, BBB {
  types: boolean
  change: () => boolean
  name: string
  getName: () => string
}
//最后，创建这个帮助函数，帮我们做混入操作。 它会遍历mixins上的所有属性，并复制到目标上去，把之前的占位属性替换成真正的实现代码
Mixins(C, [AAA, BBB])
function Mixins(curCls: any, itemCls: any[]) {
  itemCls.forEach(item => {
    Object.getOwnPropertyNames(item.prototype).forEach(name => {
      curCls.prototype[name] = item.prototype[name]
    })
  })
}